import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import httpServer from '@src/service/httpServer' // axios拦截器配置
import '@/permission' // 权限控制
import * as mUtils from '@/common/js/mUtils'
import config from '@/config'
import filters from './filters/index'
import AES from '@/common/js/secret'
import * as API from '@/api/index'

import Element from 'element-ui'
import '@/common/styles/element-variables.scss'
import '@/common/styles/index.scss' // 自定义 css
import 'animate.css'

import VueClipboard from 'vue-clipboard2'
import EventBus from './eventBus/index'

import '@/base/theme/default/index.scss'
import YouDu from '@/base/index'// 自定义基础组件
Vue.use(YouDu)

import vdr from 'vue-draggable-resizable-gorkys'
import 'vue-draggable-resizable-gorkys/dist/VueDraggableResizable.css'
Vue.component('vdr', vdr)

// 将自动注册所有组件为全局组件
import dataV from '@jiaminghi/data-view'
Vue.use(dataV)

// 引入 v-echarts
import ECharts from 'vue-echarts'
import { use } from 'echarts/core'

// import ECharts modules manually to reduce bundle size
import {
  CanvasRenderer
} from 'echarts/renderers'
import {
  BarChart,
	PieChart,
	LineChart,
	GaugeChart,
	RadarChart,
	LinesChart,
	EffectScatterChart,
	ScatterChart
} from 'echarts/charts'
import {
  GridComponent,
  TitleComponent,
	TooltipComponent,
	LegendComponent,
	PolarComponent,
	ToolboxComponent,
	VisualMapComponent
} from 'echarts/components'
use([
  CanvasRenderer,
  BarChart,
	PieChart,
	LineChart,
	GaugeChart,
	RadarChart,
	LinesChart,
	ScatterChart,
	EffectScatterChart,
  GridComponent,
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  PolarComponent,
  ToolboxComponent,
	VisualMapComponent
])
// register globally (or you can do it locally)
Vue.component('v-chart', ECharts)

Vue.use(Element);
Vue.use(VueClipboard)

/* 引用视频播放器组件 */
import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)

/**
 * 引入公共方法mUtils
 */
Vue.prototype.$mUtils = mUtils;
Vue.prototype.AES = AES
Vue.prototype.$axios = httpServer;

Vue.prototype.$api = API;
Vue.prototype.$API = API;
Vue.prototype.$bus = EventBus

/**
 * 公共配置信息
 */
Vue.prototype.$config = config
//监控窗体的大小
window.addEventListener('resize', function(){
	Vue.prototype.$window = {
		clientWidth: document.body.clientWidth,
		clientHeight: document.body.clientHeight,
		offsetWidth: document.body.offsetWidth,
		offsetHeight: document.body.offsetHeight
	}
	EventBus.$emit('winowResize')
})
Vue.prototype.$window  =  {
	clientWidth: document.body.clientWidth,
	clientHeight: document.body.clientHeight,
	offsetWidth: document.body.offsetWidth,
	offsetHeight: document.body.offsetHeight
}

// 注册全局过滤器
Object.keys(filters).forEach(key => {
	Vue.filter(key, filters[key])
})



// 登录后跳转方法
Vue.prototype.goBeforeLoginUrl = () => {
	let url = mUtils.Cookie.get('beforeLoginUrl')
	url = decodeURIComponent(url)
	if (!url || url.indexOf('/author') != -1) {
		router.push('/')
	} else {
		router.push(url)
		mUtils.Cookie.set('beforeLoginUrl', '', 1 / 24 / 60, window.location.host, window.location.pathname.substring(0, window.location.pathname.length - 1))
	}
};


String.prototype.replaceAll = function(s1, s2) {
	return this.replace(new RegExp(s1, "gm"), s2);
}

Vue.config.productionTip = false

store.commit('UPDATE_USER_FROM_LOCAL')

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
